<?

function strip_outer_tags($s) {
    
    return str_replace(array("<html>", "<body>", "</html>", "</body>"), "", $s); 
}

function load_top_info() {

	$doc = new DomDocument;
	
	@session_start();

    if(isset($_SESSION["userid"])) { 
		@$doc->loadHTMLFile("html/login.html");
		$node = $doc->getElementById("user_name");
		$node->appendChild(new DOMText(" ".$_SESSION["username"]));
		echo(strip_outer_tags($doc->saveHTML()));
	} else {
		@$doc->loadHTMLFile("html/nologin.html");
		echo(strip_outer_tags($doc->saveHTML()));
	}


}

function load_footer() {

	$doc = new DomDocument;

    if(isset($_SESSION["userid"])) { 
		@$doc->loadHTMLFile("html/footer.html");
		echo(strip_outer_tags($doc->saveHTML()));
	} else {
		@$doc->loadHTMLFile("html/footer.html");
		echo(strip_outer_tags($doc->saveHTML()));
	}
}

function load_pobox() {

	$doc = new DomDocument;

    if(isset($_SESSION["userid"])) { 
		@$doc->loadHTMLFile("html/pobox.html");
		echo(strip_outer_tags($doc->saveHTML()));
	} else {
		@$doc->loadHTMLFile("html/pobox.html");
		echo(strip_outer_tags($doc->saveHTML()));
	}
}

function load_searchbox() {

	$doc = new DomDocument;

    if(isset($_SESSION["userid"])) { 
		@$doc->loadHTMLFile("html/searchbox.html");
		echo(strip_outer_tags($doc->saveHTML()));
	} else {
		@$doc->loadHTMLFile("html/searchbox.html");
		echo(strip_outer_tags($doc->saveHTML()));
	}
}


function load_main_menu() {

	$doc = new DomDocument;

    if(isset($_SESSION["userid"])) { 
		@$doc->loadHTMLFile("html/main_menu.html");
		echo(strip_outer_tags($doc->saveHTML()));
	} else {
		@$doc->loadHTMLFile("html/main_menu.html");
		echo(strip_outer_tags($doc->saveHTML()));
	}
}

function load_pobox_ext() {

	$doc = new DomDocument;

    if(isset($_SESSION["userid"])) { 
		@$doc->loadHTMLFile("html/pobox_ext.html");
		echo(strip_outer_tags($doc->saveHTML()));
	} else {
		@$doc->loadHTMLFile("html/pobox_ext.html");
		echo(strip_outer_tags($doc->saveHTML()));
	}
}

function load_misc() {


	$doc = new DomDocument;

    if(isset($_SESSION["userid"])) { 
		@$doc->loadHTMLFile("html/misc.html");
		echo(strip_outer_tags($doc->saveHTML()));
	} else {
		@$doc->loadHTMLFile("html/misc.html");
		echo(strip_outer_tags($doc->saveHTML()));
	}
}


function load_parts() {

   load_main_menu();
   load_pobox_ext();
   load_misc();

}


function list_images() {

	$files = scandir("images/");
	$c = 0;
	foreach ($files as $file) {
	    $c++;
	    if ($file == "." || $file == "..") continue;
		echo "'images/".$file."'";
		if ($c != count($files)) echo ",";
	}

}

function list_images2() {

	$files = scandir("images/map/");
	$c = 0;
	foreach ($files as $file) {
	    $c++;
	    if ($file == "." || $file == "..") continue;
		echo "'images/map/".$file."'";
		if ($c != count($files)) echo ",";
	}

}


?>